/* 用户相关 */
import request from '@/utils/request.js'
import { getFilename } from '@/utils/index'
import qs from 'uview-ui/libs/function/queryParams'

/**
  * 微信登录
  * @param {String} code      微信号
  * @param {String} encryptedData 微信加密数据
  * @param {String} iv 微信加密算法
  * @param {String} nickname  昵称
  * @param {String} avatarUrl 头像url
  * @param {String} inviteUserId 邀请者id
  */
export const wxLogin = (data) => request('/login/wechatAndPhone', 'POST', data)

/**
 * 手机号 + 验证码登录
 * @param  {String} phone      手机号
 * @param  {String} code       验证码
 * @param  {String} wxCode     微信号
 * @param  {String} nickname   昵称
 * @param  {String} avatarUrl  头像url
 * @param {String} inviteUserId 邀请者id
 */
export const phoneLogin = (data) => request('/login/phoneAndCode', 'POST', data)

/**
  * 通过userId登录
  * @param {Number} userId
  */
export const userIdLogin = (userId) => request('/login/userId', 'GET', { userId })

/**
  * 退出登录
  */
export const loginOut = () => request('/logout ', 'GET')

/**
 * 获取个人信息
 * @param {Boolean} hold 请求失败是否不跳转登录
 */
export const getMe = (hold = false) => request('/userInfo/me', 'GET', {}, { hold })

/**
 * 修改个人基本资料
 * @param {Number}  userId
 * @param {String}  nickname
 * @param {String}  avatarUrl
 */
export const putMe = (data) => request('/userInfo/me', 'PUT', data)

/**
 * 根据userId获取用户详细信息
 * @param {Number}  userId
 */
export const getUserById = (userId) => request(`/userInfo/${ userId }`, 'GET')

/**
 * 获取自己的简历
 */
export const getMyResume = () => request('/resume/me', 'GET')

/**
 * 获取简历信息
 * @param {Number}  userId
 */
export const getResume = (userId) => request(`/resume/${ userId }`, 'GET')

/**
 * 更新简历信息
 * @param {Number}  userId
 * @param {String}  name,phone,email,gender,birth,highestDegree,identity,currentGrade,workPlace,profession,projectSkill,intro
 * @param {Array}  eduExperiences,schoolExperiences,projectExperiences,practiceExperiences,honors
 */
export const putResume = (data) => request('/resume', 'PUT', data)

/**
 * 获取未读通知数量
 */
export const getUnreadCount = () => request('/message/count/notRead/all ', 'GET', {})

/**
 * 获取个人购买的项目附件
 * @param {String} keyWord
 */
export const getPurchased = (params) => request('/project/resource/purchased/search', 'GET', params)

/**
 * 获取指定用户统计数据
 * @param {Number}  userId
 */
export const getUserStatistics = (userId) => request(`/statistics/${ userId }`, 'GET')

/**
 * 获取指定用户关注数量
 * @param {Number}  userId
 */
export const getUserFollowersNum = (userId) => request(`/user/othersFollowersLen/${ userId }`, 'GET')

/**
 * 获取指定用户粉丝数量
 * @param {Number}  userId
 */
export const getUserFansLen = (userId) => request(`/user/othersFansLen/${ userId }`, 'GET')

/**
 * 获取用户轨迹
 * @param {Number}  userId
 * @param {Number}  type
 */
export const getUserTracks = (userId, type) => request(`/user/track/${ userId }${ qs({ type }) }`, 'GET')

/**
 * 获取实名认证上传签名
 * @param {String}  filename
 */
export const getAuthenticationSignature = (filename) => request(`/authentication/sign/upload?filename=${ getFilename(filename) }`, 'GET')

/**
 * 提交实名认证信息
 */
export const putAuthentication = (data) => request(`/authentication/updatePersonalAuthentication`, 'PUT', data)

/**
 * 判断用户与自己关系
 * @param {Number}  userId 对方ID
 */
export const getUserRelation = (userId) => request(`/user/relation/${ userId }`, 'GET')

/**
 * 关注用户
 * @param {Number}  userId 对方ID
 */
export const followUser = (userId) => request(`/user/follow/${ userId }`, 'POST')

/**
 * 取消关注
 * @param {Number}  userId 对方ID
 */
export const unFollowUser = (userId) => request(`/user/unfollow/${ userId }`, 'POST')

/**
 * 策略获取人才
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 */
export const getTalents = (params) => request('/talentMarket', 'GET', params)

/**
 * 获取用户收藏统计
 */
export const getCollectCount = () => request('/user/collection/all', 'GET')

/**
 * 获取项目数量收藏统计
 */
export const getProjectStatic = () => request('/userOperate/getResourceNumInvolved', 'GET')

/**
 * 获取我的关注/粉丝列表
 * @param {String} targetType 粉丝fan，关注follow
 * @param {String} keyWord 关键字
 * @param {Number} pageNum
 * @param {Number} pageSize
 */
export const getMyFollowersOrFans = (params) => request('/user/searchFollowsOrFans', 'GET', params)

/**
 * 获取用户列表
 * @param {String} keyWord 关键字
 * @param {Number} pageNum
 * @param {Number} pageSize
 */
export const getUserList = (params) => request('/userOperate/getUserRoughInfoByVague', 'GET', params)

/**
 * 获取历史访问记录
 */
export const getProjectHistory = (params) => request(`/projectHistoryRecord`, 'GET', params)

/**
 * 获取指定用户参会的所有项目
 */
export const getUserProjects = (userId) => request(`/user/track/allProjectPassed/${ userId }`, 'GET')

/**
 * 判断今天是否签到
 */
export const checkDaySignIn = (myUserId) => request(`/userSignIn/finishedSignIn`, 'GET', { id: myUserId })

/**
 * 签到
 */
export const daySignIn = (myUserId) => request(`/userSignIn/signIn/${ myUserId }`, 'GET')

/**
 * 赠送aha币
 * @param {Number} targetUserId 目标userId
 * @param {Number} creditAmount 点数
 */
export const giveAhaCredit = (params) => request(`/userOperate/giveawayCredit${ qs(params) }`, 'PUT')
